package com.sx.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.dbutils.handlers.MapListHandler;

import com.annotation.BaseService;

public class WeatherKnowService {
	/**
	 * 百科知识
	 * @param request
	 * @return
	 * @throws SQLException
	 */
	public  List<Object>  baikeList(HttpServletRequest request) throws SQLException {
		
		int size=Integer.parseInt(request.getParameter("size"));
		int page=Integer.parseInt(request.getParameter("page"));
		int num=((page-1)*size);
		String sql="select id,img,title from d_weather_know limit "+num+","+size;
		List<Object> list = new ArrayList<>();
    	list.add(BaseService.queryList(sql, null));
		return list;
	} 
	/**
	 * 查询详情
	 * @param request
	 * @return
	 * @throws SQLException
	 */
	public  List<Object>  baikeDetails(HttpServletRequest request) throws SQLException {
			
			String id=request.getParameter("id");
			String sql="select description,creat_time from d_weather_know where id="+id;
			List<Object> list = new ArrayList<>();
	    	list.add(BaseService.queryList(sql, null));
			return list;
		} 
        
	
	/**
	 * 气象百科信息检索
	 * @param request
	 * @return
	 * @throws SQLException
	 */
		public  List<Object>  baikeSearch(HttpServletRequest request) throws SQLException {
		int size=Integer.parseInt(request.getParameter("size"));
		int page=Integer.parseInt(request.getParameter("page"));
		String  keyWords=request.getParameter("keyword");
		int num=((page-1)*size);
		String sql="select id,img,title from d_weather_know where title like '%"+keyWords+"%' OR description like '%"+keyWords+"%' limit "+num+","+size;
		List<Object> list = new ArrayList<>();
    	list.add(BaseService.queryList(sql, null));
		return list;
	}
	
}
